/**
 * Created by zhangzhihao on 2016/12/06 11:00;
 */
var vm = new Vue({
    el: "#main",
    data: {
        tipid: "", // 提示id
        tipCode: '', //提示编码
        productCode: "", // 产品编码
        productName: "", // 产品名称
        tipVersion: "", //提示信息版本号
        businessCode: "", // 业务编码
        tipMode: "", // 提示模板
        tipMessage: "", // 提示信息
        promptItem: {},
        tips: "",
        disableShow: false,
        disableShow1: true,
        phoneBoxShow:true
    },
    created: function() {
        const _this = this;
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        var openType = "";
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] == "type") {
                openType = pair[1];
                _this.openType = openType;
            }
        }

        if (_this.openType != "04") {
            _this.promptItem = JSON.parse(sessionStorage.getItem("promptItem"));
            console.log(_this.promptItem);
            _this.tipid = _this.promptItem.tipid;
            _this.productCode = _this.promptItem.productCode;
            _this.productName = _this.promptItem.productName;
            _this.tipCode = _this.promptItem.tipCode;
            _this.tipVersion = _this.promptItem.tipVersion;
            _this.businessCode = _this.promptItem.businessCode;
            _this.tipMode = _this.promptItem.tipMode;
            _this.tipMessage = _this.promptItem.tipMessage;
        }
        if (_this.openType == '01') {
            //查看
            _this.disableShow = true
        } else if (_this.openType == '02') {
            //编辑
            _this.disableShow = false
        } else if (_this.openType == '03') {
            //复制
            // _this.disableShow = true
            _this.disableShow1 = false
        }
    },
    methods: {
        //修改进入初始化
        modinit: function() {
            $("#mod").css("display", "");
            _data = {};
            url = location.search.split("=");
            _data.id = url[1];
            App.ajax({
                type: "POST",
                url: App.getApiUrl("modfriend"),
                data: _data,
                success: function(data) {
                    $("#friend_no").val(data.OPT_NO);
                    $("#friend_name").val(data.OPT_NAME);
                    $("#mod_optid").val(data.OPT_ID);
                    $("#mod_id").val(data.id);
                    if (data.companyType == 1) {
                        $("#leixing .am-fl").text("保险");
                        $("#lei").val(data.companyType);
                    }
                    if (data.OPT_STATUS == 1) {
                        $("#stats .am-fl").text("有效");
                        $("#sta").val(data.OPT_STATUS);
                    } else {
                        $("#stats .am-fl").text("无效");
                        $("#sta").val(data.OPT_STATUS);
                    }
                    $("#beginDay").val(data.applicationDate);
                    $("#phone").val(data.phone);
                    $("#email").val(data.email);
                },
            });
        },
        //新增方法
        submit_add: function() {
            const _this = this;
            var message = "";
            if (!_this.productCode) {
                // parent.showAlert("请输入公司名称");
                message = "请输入产品编码";
            } else if (!_this.productName) {
                message = "请输入产品名称";
            } else if (!_this.tipVersion) {
                message = "请输入版本号";
            } else if (!_this.tipCode) {
                message = "请输入提示语key键";
            } else if (!_this.businessCode) {
                message = "请输入业务场景";
            } else if (!_this.tipMode) {
                message = "请输入提示模板";
            } else if (!_this.tipMessage) {
                message = "请输入提示信息";
            }
            if (message) {
                $("#my-alert1").modal({
                    relatedTarget: this,
                });
                this.tips = message;
                return;
            }
            var obj = {
                productCode: _this.productCode, // 产品编码
                productName: _this.productName, // 产品名称
                tipCode: _this.tipCode, // 提示编码
                tipVersion: _this.tipVersion, //提示信息版本号
                businessCode: _this.businessCode, // 业务编码
                tipMode: _this.tipMode, // 提示模板
                tipMessage: _this.tipMessage, // 提示信息
            };
            if (_this.openType == "01" || _this.openType == "02") {
                obj.tipId = _this.tipid;
                //修改或者查询
                axios({
                        method: "post",
                        url: App.envUrl.backtrackUrl + "/tipMessage/TipUpdate",
                        data: obj,
                    })
                    .then((data) => {
                        console.log(data.data.data);
                        window.location.href = "prompt.html";
                    })
                    .catch((err) => {});
            } else if (_this.openType == "03" || _this.openType == "04") {
                //新增
                axios({
                        method: "post",
                        url: App.envUrl.backtrackUrl + "/tipMessage/TipSave",
                        data: obj,
                    })
                    .then((data) => {
                        console.log(data.data.data);
                        window.location.href = "prompt.html";
                    })
                    .catch((err) => {});
            }
        },
        backTo: function() {
            window.location.href = "prompt.html";
        },
        //手机演示
        phoneBox(){
            this.phoneBoxShow = true;
            document.querySelector('.rrweb-toast_agree span').className = '';
            $("#my-alert").modal({
                relatedTarget: this,
            });
        },
        toastSbClick(){
            if(document.querySelector('.rrweb-toast_agree span').className === ''){
                return;
            }else{
                this.phoneBoxShow = false;
            }
        }
    },
});